const path = require('path');


// https://github.com/jantimon/html-webpack-plugin
var HtmlWebpackPlugin = require('html-webpack-plugin'); //打包html的插件
const CompressionPlugin = require('compression-webpack-plugin');

console.log("process.env.NODE_ENV");
console.log(process.env.NODE_ENV);

module.exports = {
  mode: 'development',
  entry: './src/index.js',
  module: {
    rules: [
      {
        test: /\.css$/i,
        use: ['style-loader', 'css-loader'],
      },
      {
        test: /\.(png|svg|jpg|jpeg|gif)$/i,
        type: 'asset/resource',
      },
    ],
  },
  output: {
    // 单文件打包
    // filename: 'main.js',
    filename: './js/[name].js',
    path: path.resolve(__dirname, 'dist'),
    clean: true
  },
  devServer: {
    static: './dist',
  },
  // https://webpack.docschina.org/guides/development/#using-source-maps
  // devtool: 'inline-source-map',
  devtool: 'cheap-source-map',
  plugins: [new HtmlWebpackPlugin({
    title: '个人webPack',
    filename: "index.html"
  }
  ),
  new CompressionPlugin(
    {
      algorithm: 'gzip',
    }
  )],
  // https://webpack.docschina.org/guides/code-splitting/
  optimization: {
    splitChunks: {
      chunks: 'all',
    },
  },

};